<template>
    <div>
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :span="6">
                        <a-form-model-item label="搜索内容">
                            <a-input v-model="queryParam.storeName" placeholder="请输入序号、姓名、手机号、菜品、门店的关键字" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="9">
                        <a-form-model-item label="提交时间">
                            <a-date-picker :show-time="{ format: 'HH:mm' }" format="YYYY-MM-DD HH:mm" placeholder="开始时间"
                                @change="(value, dateString) => onChange(value, dateString, 'timeBegin')" />
                            -
                            <a-date-picker :show-time="{ format: 'HH:mm' }" format="YYYY-MM-DD HH:mm" placeholder="结束时间"
                                @change="(value, dateString) => onChange(value, dateString, 'timeEnd')" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="9">
                        <a-form-model-item label="付款时间">
                            <a-date-picker :show-time="{ format: 'HH:mm' }" format="YYYY-MM-DD HH:mm" placeholder="开始时间"
                                @change="(value, dateString) => onChange(value, dateString, 'timeBegin1')" />
                            -
                            <a-date-picker :show-time="{ format: 'HH:mm' }" format="YYYY-MM-DD HH:mm" placeholder="结束时间"
                                @change="(value, dateString) => onChange(value, dateString, 'timeEnd2')" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="5">
                        <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                            <a-button type="primary" @click="searchReset" icon="reload"
                                style="margin-left: 8px">重置</a-button>
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
            <!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
            <!--      <a-button type="primary" icon="download" @click="handleExportXls('订单')">导出</a-button>-->
            <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
            <!--        <a-button type="primary" icon="import">导入</a-button>-->
            <!--      </a-upload>-->
            <!-- 高级查询区域 -->
            <!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
            <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
            <!--        <a-menu slot="overlay">-->
            <!--          <a-menu-item key="1" @click="batchDel">-->
            <!--            <a-icon type="delete"/>-->
            <!--            删除-->
            <!--          </a-menu-item>-->
            <!--        </a-menu>-->
            <!--        <a-button style="margin-left: 8px"> 批量操作-->
            <!--          <a-icon type="down"/>-->
            <!--        </a-button>-->
            <!--      </a-dropdown>-->
        </div>

        <!-- table区域-begin -->
        <div>
            <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
            <!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
            <!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
            <!--      </div>-->

            <a-table ref="table" size="middle" :scroll="{ x: true }" :bordered="false" rowKey="id" :columns="columns"
                :dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
                @change="handleTableChange">
                <template slot="complaintCountSlot" slot-scope="text, record">
                    <a @click="handleListModal(record)">{{ text + '次' }}</a>
                </template>
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text, record">
                    <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
                    <template v-else>
                        <img :src="getImgView(item)" :preview="record.id" v-for="(item, index) in text.split(',')"
                            height="25px" alt=""
                            style="max-width: 80px; font-size: 12px; font-style: italic;margin-right:5px" :key="index" />
                    </template>
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
                    <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                        下载
                    </a-button>
                </template>

                <span slot="action" slot-scope="text, record">
                    <span v-if="record.state != '未处理'">已处理</span>
                    <template v-if="record.hcOrderMerchant.companyName">
                        <a @click="showReturn('company', record)" v-if="record.state == '未处理'">同意</a>
                        <a @click="showReject('company', record)" style="margin-left: 5px"
                            v-if="record.state == '未处理'">拒绝</a>
                    </template>
                    <template v-else>
                        <a @click="showReturn('personal', record)" v-if="record.state == '未处理'">售后退款</a>
                        <a @click="showReject('personal', record)" style="margin-left: 5px"
                            v-if="record.state == '未处理'">驳回</a>
                    </template>


                    <!-- <a @click="showReturn(record)">售后退款</a>
            <a @click="showReject(record)" style="margin-left:5px">驳回</a> -->
                    <!--          <a-divider type="vertical"/>-->
                    <!--          <a-dropdown>-->
                    <!--            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>-->
                    <!--            <a-menu slot="overlay">-->
                    <!--              <a-menu-item>-->
                    <!--                <a @click="handleDetail(record)">详情</a>-->
                    <!--              </a-menu-item>-->
                    <!--              <a-menu-item>-->
                    <!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
                    <!--                  <a>删除</a>-->
                    <!--                </a-popconfirm>-->
                    <!--              </a-menu-item>-->
                    <!--            </a-menu>-->
                    <!--          </a-dropdown>-->
                </span>
            </a-table>
        </div>
        <ReturnMoney ref="returnMoney" @loadData="loadData"></ReturnMoney>
        <RejectOrder ref="rejectOrder" @loadData="loadData"></RejectOrder>
        <hc-merchant-after-sales-list-modal ref="HcMerchantAfterSalesListModal" />
    </div>
</template>
  
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ReturnMoney from './returnMoney.vue'
import RejectOrder from './rejectOrder.vue'
import HcMerchantAfterSalesListModal from "@views/hc/HcMerchantAfterSalesListModal.vue";

export default {
    name: 'HcOrderList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
        HcMerchantAfterSalesListModal,
        ReturnMoney,
        RejectOrder,
    },
    data() {
        return {
            description: '订单管理页面',
            // 表头
            columns: [
                {
                    title: '#',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: "center",
                    fixed: "left",
                    customRender: function (t, r, index) {
                        return parseInt(index) + 1;
                    }
                },
                {
                    title: '门店名称',
                    align: 'center',
                    dataIndex: 'storeName'
                },
                {
                    title: '序号',
                    align: 'center',
                    dataIndex: 'hcOrderMerchant.pickingSerialNo'
                },
                {
                    title: '姓名',
                    align: 'center',
                    dataIndex: 'hcOrderMerchant.nameTakingMeal'
                },
                {
                    title: '地址',
                    align: 'center',
                    dataIndex: 'hcOrderMerchant.pickingAddress'
                },
                {
                    title: '手机',
                    align: 'center',
                    dataIndex: 'hcOrderMerchant.phoneTakingMeals'
                },
                {
                    title: '菜品',
                    align: 'center',
                    dataIndex: 'nameDishes',
                },
                {
                    title: '消费金额',
                    align: 'center',
                    dataIndex: 'totalPrice',
                },
                {
                    title: '餐品问题',
                    algin: 'center',
                    dataIndex: 'foodProblems',
                },
                {
                    title: '图片',
                    algin: 'center',
                    dataIndex: 'picture',
                    scopedSlots: { customRender: 'imgSlot' },
                },
                {
                    title: '投诉建议',
                    algin: 'center',
                    dataIndex: 'feedback',
                },
                {
                    title: '付款时间',
                    algin: 'center',
                    dataIndex: 'hcOrderMerchant.createTime'
                },
                {
                    title: '提交时间',
                    align: 'center',
                    dataIndex: 'createTime',
                },
                {
                    title: '处理时间',
                    align: 'center',
                    dataIndex: 'processingTime',
                },
                {
                    title: '处理状态',
                    algin: 'center',
                    dataIndex: 'state',
                },
                {
                    title: '退款金额',
                    algin: 'center',
                    dataIndex: 'refundAmount',
                    customRender: (value, row, index) => {
                        return value || value == '0' ? value : '无'
                    },
                },
                {
                    title: '扣除商家金额',
                    algin: 'center',
                    dataIndex: 'deductMerchantAmount',
                    customRender: (value, row, index) => {
                        return value || value == '0' ? value : '无'
                    },
                },
                {
                    title: '扣除备注',
                    algin: 'center',
                    dataIndex: 'deductionRemarks',
                    customRender: (value, row, index) => {
                        return value ? value : '无'
                    },
                },
                {
                    title: '驳回原因',
                    algin: 'center',
                    dataIndex: 'reasonRejection',
                    customRender: (value, row, index) => {
                        return value ? value : '无'
                    },
                },
                {
                    title: '门店累计投诉次数',
                    algin: 'center',
                    dataIndex: 'complaintCount',
                    scopedSlots: { customRender: 'complaintCountSlot' }
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    align: 'center',
                    fixed: "right",
                    width: 147,
                    scopedSlots: { customRender: 'action' },
                },
            ],
            url: {
                list: '/hc/hcAfterSales/list',
                delete: '/hc/hcOrder/delete',
                deleteBatch: '/hc/hcOrder/deleteBatch',
                exportXlsUrl: '/hc/hcOrder/exportXls',
                importExcelUrl: 'hc/hcOrder/importExcel',
            },
            dictOptions: {},
            superFieldList: [],
        }
    },
    created() {
        this.getSuperFieldList()
    },
    computed: {
        importExcelUrl: function () {
            return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
        },
    },
    methods: {
        handleListModal: function (record) {
            this.$refs.HcMerchantAfterSalesListModal.open('personal',record);
            this.$refs.HcMerchantAfterSalesListModal.title = record.storeName + " 售后订单列表";
            this.$refs.HcMerchantAfterSalesListModal.disableSubmit = false;
        },
        onChange(value, dateString, field) {
            console.log('Selected Time: ', value);
            console.log('Formatted Selected Time: ', dateString);
            this.$set(this.queryParam, field, dateString);
        },
        //展示退款弹窗
        showReturn(type, value) {
            this.$refs.returnMoney.show(type, value);
        },
        //展示拒绝弹窗
        showReject(type, value) {
            this.$refs.rejectOrder.show(type, value);
        },
        getSuperFieldList() {
            let fieldList = []
            fieldList.push({ type: 'string', value: 'userId', text: '用户ID' })
            fieldList.push({ type: 'string', value: 'state', text: '状态' })
            fieldList.push({ type: 'int', value: 'pickingSerialNo', text: '取餐序号' })
            fieldList.push({ type: 'string', value: 'pickingAddress', text: '取餐地址' })
            fieldList.push({ type: 'number', value: 'totalPrice', text: '总价格' })
            this.superFieldList = fieldList
        }
    },
}
</script>
<style scoped>
@import '~@assets/less/common.less';

::v-deep table tbody tr:hover>td {
    background-color: #ffffff !important;
}</style>